
<html>

	<head>
		<meta charset="utf-8" />
		<title>第一节课</title>
		<style type="text/css">
			/*去除原来样式*/
			
			* {
				padding: 0;
				margin: 0;
			}
			
			.container {
				width: 100vw;
				height: 100vh;
				display: flex;
				/*
				 * 将边框设置在中间
				 */
				align-items: center;
				justify-content: center;
			}
			
			canvas {
				width: 500px;
				height: 500px;
				border: 1px solid #333333;
			}
		</style>
	</head>

	<body>
		<div class="container">
			<canvas id="canvas" width="500" height="500"></canvas>
		</div>
	</body>

	<script>
		
		window.onload = function() {
			//let oCanvas = document.getElementById('canvas');
			let oCanvas = document.getElementById("canvas");
			let pen = oCanvas.getContext("2d");
			
			/*document.onmousemove = function(e){
				console.dir("x="+(e.pageX-oCanvas.offsetLeft));
				console.dir("y="+(e.pageY-oCanvas.offsetTop));
			}
			
			document.onmousedown = function(e){
				console.dir("x="+(e.pageX-oCanvas.offsetLeft));
				console.dir("y="+(e.pageY-oCanvas.offsetTop));	
			}
			
			document.onmouseup = function(e){
				console.dir("x="+(e.pageX-oCanvas.offsetLeft));
				console.dir("y="+(e.pageY-oCanvas.offsetTop));
			}*/
		
			
			
			document.onmousedown = function(e){
				
				pen.moveTo((e.pageX-oCanvas.offsetLeft),(e.pageY-oCanvas.offsetTop))
					document.onmousemove = function(e){
							pen.lineTo((e.pageX-oCanvas.offsetLeft),(e.pageY-oCanvas.offsetTop))
							pen.stroke();
					}
				
			}
			
				document.onmouseup = function(e){
					document.onmousemove=null;
				}
				
			
			
			
			
		}
	</script>

</html>